﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace csharp_host2ip
{
    class Program
    {
        static void Main(string[] args)
        {
            IPHostEntry ipEntry;
            IPAddress[] ipAddr;
            char[] alpha = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ-".ToCharArray();

            Console.Write("input host: ");
            string str_in = Console.ReadLine();

            if (str_in.IndexOfAny(alpha) != -1)
            {
                ipEntry = Dns.GetHostByName(str_in);
                ipAddr = ipEntry.AddressList;

                for (int i = 0; i < ipAddr.Length; i++)
                {
                    Console.WriteLine(ipAddr[i].ToString());
                }
            }
            else
            {
                ipEntry = Dns.Resolve(str_in);
                Console.WriteLine(ipEntry.HostName);
            }

            Console.WriteLine("Press Anykey");
            Console.ReadKey();
        }
    }
}
